<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>添加一行</button>
    <table border="1">
        <tr bgColor="grey">
            <td>服装</td>
            <td>家具</td>
            <td>家点</td>
            <td>操作</td>
        </tr>
    </table>
    <script>
        var btn = document.querySelector("button");
        var tab = document.querySelector("table")
        btn.onclick = function(){
            /* 创建tr */
            var tr = document.createElement("tr");
            for(var i = 0 ; i < 3 ; i ++){
                /* 创建三个td */
                var td = document.createElement("td")
                switch(i){
                    case 0:
                        td.innerHTML = prompt("请输入一个服装")
                        break;
                    case 1:
                        td.innerHTML = prompt("请输入一个家具")
                        break;
                    case 2:
                        td.innerHTML = prompt("请输入一个家电")
                        break;
                }
                /* 将td追加到tr后 */
                tr.appendChild(td)
            }

            var td = document.createElement("td");
            /* 时间戳 */
            var tid = Date.now();
            td.setAttribute("id","data-"+tid)
           
            td.innerHTML = '<a href="javascript:del('+tid+');">删除</a>'
            tr.appendChild(td)

            /* tr追加到table后 */
            tab.appendChild(tr)
        }

        /* 伪链接的调用,删除tr */
        function del(tid){
            var td = document.getElementById("data-"+tid)
            console.log(td.parentNode.parentNode.removeChild(td.parentNode));
        }
    </script>
</body>
</html>